﻿$(function () {
    var submitFilterForm = function() {
        $("filterForm").submit();
        return false;
    };

    $("#todayFilter").click(function () {
        var todayDate = new Date();
        var todayAsString = todayDate.getMonth()+1 + "/" + todayDate.getDate() + "/" + todayDate.getFullYear();
        $("#fromDate").attr("value", todayAsString);
        $("#toDate").attr("value", todayAsString);
        return submitFilterForm();
    });
    
    $("#weekFilter").click(function () {
        var todayDate = new Date();
        var fromDate = new Date();
        fromDate.setMonth(todayDate.getMonth());
        fromDate.setDate(todayDate.getDate() - 7);
        
        var todayAsString = todayDate.getMonth()+1 + "/" + todayDate.getDate() + "/" + todayDate.getFullYear();
        var fromAsString = fromDate.getMonth()+1 + "/" + fromDate.getDate() + "/" + fromDate.getFullYear();
        
        $("#fromDate").attr("value", fromAsString);
        $("#toDate").attr("value", todayAsString);
        return submitFilterForm();
    });
    
    $("#monthFilter").click(function () {
        var todayDate = new Date();
        var fromDate = new Date();
        fromDate.setMonth(todayDate.getMonth()-1);
        fromDate.setDate(todayDate.getDate());

        var todayAsString = todayDate.getMonth()+1 + "/" + todayDate.getDate() + "/" + todayDate.getFullYear();
        var fromAsString = fromDate.getMonth()+1 + "/" + fromDate.getDate() + "/" + fromDate.getFullYear();
        $("#fromDate").attr("value", fromAsString);
        $("#toDate").attr("value", todayAsString);
        return submitFilterForm();
    });
    
    $("#fromDate").datepicker();
    $("#toDate").datepicker();
});